﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Bdcs.Application.Mappers.Dto;
using Bdcs.Core.Entity;
using Furion.DatabaseAccessor;
using Furion.DynamicApiController;
using Mapster;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;

namespace Bdcs.Application.Services
{
    /// <summary>
    /// 部门管理接口
    /// </summary>
    [ApiDescriptionSettings("部门管理接口@999")]
    public class DepartmentService : IDynamicApiController
    {
        private readonly IRepository _companyInfoRepository;

        /// <summary>
        /// 构造函数注入
        /// </summary>
        /// <param name="companyInfoRepository"></param>
        public DepartmentService(IRepository companyInfoRepository)
        {
            _companyInfoRepository = companyInfoRepository;
        }

        /// <summary>
        /// 查询用户部门信息
        /// </summary>
        /// <returns></returns>
        public List<CompanyDto> GetUserId(string userid)
        {
            var pageResult = from a in _companyInfoRepository.Change<SYS_CompanyInfoMod>().AsQueryable()
                             join b in _companyInfoRepository.Change<Adv_UserDeptMod>().AsQueryable() on a.CompanyID equals b.CompanyID into results
                             from b in results.DefaultIfEmpty()
                             select new CompanyDto
                             {
                                 CompanyID = a.CompanyID,
                                 CompanyName = a.CompanyName
                             };
            
            return pageResult.ToList<CompanyDto>();
        }

    }
}
